<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/8 0008
 * Time: 上午 11:32
 */

namespace app\sports_admin\controller;
use app\sports_admin\model\DeviceTemporaryNum as DeviceTemporaryNumaModel;
use app\sports_admin\service\DeviceTemporaryNum as DeviceTemporaryNumService;
use app\sports_admin\vaildate\DeviceTemporaryNum as DeviceTemporaryNumVaildate;
class DeviceTemporaryNum extends Base
{
    protected $beforeActionList = [
        'operationDelete'   =>  ['only'=>'delete'],
        'operationSelect'   =>  ['only'=>'add,index,numberlist,export'],
        'operationInsert'   =>  ['only'=>'insert'],
        'operationUpdate'   =>  ['only'=>'abandoning'],
    ];
    /**
     * 设备临时编号首页
     */
    public function index()
    {
        //批次号
        $batch = DeviceTemporaryNumaModel::group('batch')->select();
        //版本号
        $version = DeviceTemporaryNumaModel::group('version')->select();
        return view('index',compact('batch','version'));
    }
    /**
     * 临时编号列表
     */
    public function numberList()
    {
        return DeviceTemporaryNumService::numberList();
    }
    /**
     * 生成设备临时编号页面
     */
    public function add()
    {
        $batch = DeviceTemporaryNumaModel::max('batch');
        $batch = $batch+1;
        return view('add',compact('batch'));
    }
    /**
     * 生成设备编号
     */
    public function insertTemporaryNumber()
    {
        (new DeviceTemporaryNumVaildate())->insertTemporaryNumber();
        return DeviceTemporaryNumService::insertTemporaryNumber();
    }
    /**
     * 删除设备编号
     */
    public function delete()
    {
        (new DeviceTemporaryNumVaildate())->deleteTemporaryNumber();
        return DeviceTemporaryNumService::delete();
    }
    /**
     * 编号弃用
     */
    public function abandoning()
    {
        (new DeviceTemporaryNumVaildate())->abandoningTemporaryNumber();
        return DeviceTemporaryNumService::abandoning();
    }
    /**
     * 导出excel页面
     */
    public function export()
    {
        return view('export');
    }
    /**
     * 导出excel数据
     */
    public function exportInfo()
    {
        return DeviceTemporaryNumService::exportInfo();
    }
    /**
     * 正式编号页面
     */
    public function official()
    {
        return view('official_number');
    }
    /**
     * 生成正式编号
     */
    public function officialNumber()
    {
        return DeviceTemporaryNumService::officialNumber();
    }
}
